<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios请求方法别名</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

</head>
<body>
  <button id="btnGet">查询get请求</button>
  <button id="btnPost">新增post请求</button>
  <button id="btnUpdate">更新update请求</button>
  <button id="btnDelete">删除delete请求</button>

  <script>
    const oBtnGet = document.getElementById('btnGet')
    const oBtnPost = document.getElementById('btnPost')
    const oBtnUpdate = document.getElementById('btnUpdate')
    const oBtnDelete = document.getElementById('btnDelete')

    // 查询和删除delete的请求条件一样
    oBtnGet.onclick =async function(){
            //get请求  axios.get（'url',[配置信息]，这里只需要params）
        const re = await axios.get('/user',{
            params:{
                userID:'001'
            }
        })
        console.log(re.data);
    }
    oBtnDelete.onclick =async function(){
        const re = await axios.delete('/deleteuser',{
            params:{
                userID:'001'
            }
        })
        console.log(re.data);
    }
    


    // post和改put的请求方式一样（需要有请求体）
    oBtnPost.onclick = async function(){
        // post请求post(url[, data[, config]]) 
        //这里data就是请求体数据，其他的不需要配置
        const re = await axios.post('/adduser',{
            name:'xiaoA',
            age:'18'
        })
        console.log(re.data);
    }
    //和post一致，把要新增或者修改的数据放上去

    oBtnUpdate.onclick = async function(){
        const re = await axios.put('/updateuser',{
            name:'xiaoB',
            age:'19'
        })
        console.log(re.data);
    }

    oBtnPost
  </script>
</body>
</html>